Replaced puts and vairous hacks with printf