improved condition checking