use strlen only once