updated condition logic