Implemented  the functions and added a few tests.