Added some error handling to avoid HTTP error 500