refactor to use sql instead of sql1