Formatted output and added error checking