Basic refactoring: Move some stuff around, clean up formatting.