Clean up this code a bit.