Move module saving code out of main class