Clean up

I tried to DRY up the code a bit.