Refactor queue retrieve