reordered the sql statements