more cleanup, some work for saving and loading, further templating