Implemented neccessary functions
Added explanatory comments