replaced `print`s with stdout.write()