Implemented the two functions, added test.