minor refactoring and cleanup, appears to work fine...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>