Make sort buttons logic work