Completed refactor with tests passing