Fixed some minor bugs and added some comments