PEP 8 style changes
Wrong variable name and close connection when exception is thrown.