only allocate substr if needed