fixed bad logic