Fixed override agent sorting
Fixed threading issues
Misc refactoring