Refactor module code