code cleanup and work on #131