handle the q = r case better