Refactor the sqlite helper