updated with check for string type so indexOf doesnt break. also added test case for html entity writes of all types