Updated with sanity checks.