clean up and sql fixes