Logic for sorting results depending from user