Completed refactoring based on hlint