Further fixes for running separate instance of the API and better thread handling on import