fix bug in logic