Fixed printing to prevent extra new line at the end, and added compatibility between Python 2 and 3 with using a from __future__ import statement.