fixed wrong loop handling + unit tests -> ready for iterative image
labeling