Implemented functions

Also added comments for clarification