Added protections to avoid crashes with bad modules