Cleaned up code and removed unused variables