Code refactring. Adding sort.