Cleaning up the SQL extraction code

asdf