Fully functional version, but with lots of comments and no functions