Implementing sort rules