refactoring, references #9, fixes #1