more refactoring, working on #1