factor out debug keyword
refactor coord_iterator for improved efficiency (I hope)