fixed initialize to take XMAX into account