major rewrite of pandagl