Fix for #6. Added error handlers and encode the text before parsing