fix minor bugs and added some comments