Just for reference, this is the implementation that was discussed in #65.