Refactoring, cleanup, fix the persist behavior