Refactor queueing logic which should lead to a fix for #1