Based on patches from Robert Lipe <robertl@dgii.com>: