Encoding speed boosted by replacing vector with queue
Encoding speed boosted by replacing vector with queue