Added local sorting to the script