Fixed code and algorithm for constructing Xtilde