Refactor code to use printLn function