Minor bug fixes , added some comments