More minor code improvements and formatting
Fix headers
Fix a switch statement so that it doesn't do horrible things when a condition isn't met (seriously, this fixes a segfault with gcc)