Cleaning up and sorting code