working; passing tests. needs refactoring