check whether module is defined before undefining it