Code updated

Updated code for a few issues. Details are mentioned  in comments while committing.