Updating the code with some improvements to the way sql is consumed by the libraries.