Bug fix and code cleanup (fixes #606)

Signed-off-by: Michael Eshom <oldiesmann@oldiesmann.us>