working on Issue #92. also did some code cleanup.