using shift instead of pop