Added formatting, fixed a bug or two as well, maybe even learned something!