Implemented functions and added comments