Minor bug fixes and added some comments