Cleaned up code a fair bit.