small changes and fix sort