Bugfix. Replaced pop() with shift()