fixed bugs, added comments