Refactor to more module code