change class(object) == "lavaan" checks by inherits(object, "lavaan")