Removed unnecessary code & changed from global to local variables