Sort function plus other active record changes, some new scopes (not all being used)