improved output and sql statements