fixed invalid length issues