changed queue to list for immutability
completed code for ordering