added ability to query queue based on index, organized code