Minor optimization added and formatting done.