Bug fixes and Committing the patch provided by Lahiru