Refactored to use print and \n instead of puts