extracted redundant code into an abstract Queue class