use unsigned type for length variable