adds module class and refactors code