Removed a redundant check. And fixed and error with scope in the sort function.