refactor sql builder