added fix for issue #656 for custom sorting and ordering