many fixes in logic