fixed #19, cleanup and minor build refactoring