testing sql statements and cleaning up the code