Trying to solve deadlock