minor refactoring
fixed #160
miscellaneous fixes