changed range to xrange, and fix some formatting errors.