SQL Query standardization and error checking. Unfortunantly this was pretty much a re-write.