Refactoring of the apqueue