change $type to $m_type, I do not know why using $type will cause a problem that $type is wrong