Added checks for modules
Slight refactoring