fixing logical error