Cleaned up code structure a bit.