fixed bad condition logic