Sorting out the code a bit