Fixed crash and made the output nearly identical to the solution output.