fix lock/unlock and added some tests