Implemented required fuctionality and an addtional unit test function