added overflow detection and equals