move most of sorting logic to separate file
support user sorting

Allowed sorting fields so far are 'name' and 'joined'.