fixed error handling - fixes deadlock