Use write! instead of print! and other minor fixes