tests passing; needs refactoring