bug fixes and some comments added