fixed error in logic