Renamed functions and cleaned up code.