This MR contains a wide variety of bugfixes and code style improvements that help with debugging. They were added in the context of improving variants support, but are not causally related.