#14 fixed, minor refactoring