Cleaned up this code a bit.