Mode system rewrite

As well as a few other small changes