zagram: clean up and some bug fixing