use sys.stdout.write instead of print to prevent additional newlines