Refactoring. Only persist when actually changed. Small fixes