fixed few issues with sort