Some changes from Xistance and cleaning up