A slightly more advanced, but still not final solution to #45.