Output

Code now outputs to file rather than console.
Also, shortened the code.