Monster commit. Total reformat again in IntelliJ, and some new functionality.