Combined pull request

#6  Try again if the connection gets in a bad state
#7 Pep 8 and nitpicking 
Close cursor after use