Improved proof of concept (not tested).