Add init/close calls and write varTot rather than var