Tidies code a tiny bit.
Moves view statechart code and fixes dependency order so that reopen works correctly.