Rewrote image sorting script