Big refactoring to make the code cleaner, easier for GCC to parse or optimize,
and easier to wrap at 80 lines...