added total length checks