Added more tests and refactored higher order functions.