added testing to the sql statements. and some bug fixes!