Convert tabs to spaces

Also better comments to explain python operators
Make the script executable
Document assumptions
Use xrange to be more efficient