Added extensive sanity checks.