refactoring complete, working again