fix for issue #146 + minor code cleanup