not tested yet, but here's the general idea