Added sanity check; improved comments