Cleaned up inefficient code.