refactor lock warning and add tests