solved some bugs and added comments