Updated the get_last_error method to better handle encoding issues.