minor corrections
tidying the sql code for publication
put the sql source code into its appendix