switched to print instead of sys.stdout.write since it is faster