Fix-bugs and add comments