Updated Code with persistence