Extended persistence API, refactored some code