Groupoid schemes and algebraic stacks