Refactor into module code