rep tweak
tidying up to debug
sorting on x to get correct image