length check added, good point