code fully refactored and passing tests now with function style