fix for issue #145 + minor code cleanup