added comments for all the important functions
final submitted version