refactored into smaller methods. added multi-line output.
more accurate output