fix issue when modules are imported in a nested manner (i.e. import logging.handlers)