Give priority to completed frames and errors

Factor out some common code as well