solved error correction, modified to carry, added template