Added some error handling and character validation (to make URL encoding easier!)