Added tested code and comments

Comments added for each line and tested functions are working correctly