Clean up this atrocious mess, making it a little easier to follow