putting unlock under defer