move critical code out of assert statement