Change method of persisting and closing connection.