refactored bufferqueue
Refactored source. Eliminated a lot repetition.