WIP: Code from Alan's RMT book

I'll keep adding code to this branch from Alan's book as I go. I'm opening the pull request to track the additions and simplify commenting / questions.