Fix for safe_render. New tests are added.

For previously introduced bug in
SHA: 19924e5856dee42dbc99e4a235940394e44ad0a5