Rewrote alg2