Added additional sanity checks (length).