fix #8, minor refactoring