various fixes and refactors

The biggest thing was a race condition bugfix for instruments starting/stopping.

More refactoring to come!