check length consistency first