Some modifications in logic and updated tests