refactor and add Core Data