Corrected spacing issues,optimised code and removed global variables