new lock/unlock code (call lib routine), minor fixes