Bug fixes and added comments