Refactor queue into a struct and method