sorting fixes and enhancements for #131