Updated for Python 3 compatability

Mostly xrange -> range and using integer division operator (// instead
of just /)