write back only if result is not NULL