Implemented sorting photos before displaying.