corrected problem with sorting of x values