sorting and scoping