minor bug fixes and added comments