Trunk 4170

I have made the changes for suranga's pull request 470 of this ticket. Please review and let me know about any changes needs to done for my pull request to merge this into trunk. @dkayiwa this changes done according to your comments there in pull request 470.