Made variables global and deleted unneeded variable