Added length check to prevent wrapping.