bug fixes for issue #142
some minor code cleanup