reorder lock to avoid dead-lock