Major module handling code refactoring