Added heuristic locking algorithm