Refactored, no visible changes

Cleaned up things that were poorly-coded.