Replaced xrange with range since Python 3 doesn't have xrange