Fixed module dependencies and refactored code