Introduced read_output_data subroutine for common code. Added comments