Attempt to fix run and main class loading

There were various issues before. When we did the main class
sbt tasks, we didn't set activeTask, and therefore a run could
get going simultaneously. We didn't handle stop and restart
properly when we were doing the main class loading. Various log
messages were misleading. This tries to make it all more rational,
but it's not very comprehensible code and may need a bigger rethink.