fixed some sorting problems