Code refactoring in Module Builder

Some code refactoring in Module Builder for better code readability and organization.