#467 Updated code from pull request #530

Still no visual confirmation on the html view, but here's the stuff so far.

Test cases pass.