optimized construction of X string