Renamed stuff and cleaned up the code