implemented sorting of images