Closes connection gracefully