Added cleanup of buffers as instructed in issue #290.