Tidied up code.  Python3 compatible with updated print function.