fix iterating bugs and edge printing