karthik | Bug1&Bug2 | refactored the code.