implemented the two requested functions and added a few unit tests