make sure lock is available before functions use it, fixes #6.