md5 library is depricated so reimplemented with hashlib.
tidy up sql strings