bugfix - moved sanity check to the right place