Fixed deadlock. Not production ready, contains debug prints and syncs