Moved handling of commands into a separate thread so listening for connections won't block