Implemented the functions and added comments