Added support for modules and refactored