Formatted output and added sample input

1) Split code into functions for better organizing
2) Added formating and order to output to make it look better
3) Tested it with a public domain book
Merge branch 'master' of https://github.com/cpallares/2040