stringify value
refactoring to handle error more straightforward