refactor handler and sqlite CRUD