Restructure: More code from main into a module