Refactoring of sqlhandler