Null checks for connection, fixed improper call to setup(), other small changes