Added safe relock function 

Required a changed in the lock function to return the lock ID instead of the unlock callback.