some better condition checking