implementing master key logic