Better lock handling, fix inFlightId reset issue