Minor bug fixes and added comments