fixing linear arithmetics and a bug