Rewrite to store data in SQLite