Refactor the code in module form.