Removed some unused variables and cleaned up code