Sort by likes; refactor some logic to controller

Woops, how did I forget this?