Fixed bugs, added comments