fixed wrong length check