Most sort functions implemented

Foreign keys are still sorted by id instead of name. Needs to be fixed