Fixed minor bugs, and added comments