Tidy up and refactoring of the module