Used class property instead of local variable
Refactored processing of safePersist to work also with not autogenerated identifiers