Rough solution to #9, to very elegant yet.