Refactor for db script