smarter printing code