Cleaned up/reordered code a bit. Misc changes.