refactored to avoid duplicate setting buffers