Fixed a small bug. Removed unneeded global variables.