q is never 0, so don't need to check