Added error checking code to 'toreal' and 'tostring'