ported code to use queuelib