Reworked control port implementation using control thread, fix shutting down application