Fixed the url encoding issue for languages
Adding more error checking