Tests passing; refactored