updated the file with the extra logic to handle external urls