Improvements to #20 implementation.