refactor file locking so we don't repeat ourselves quite so often