first go at this, not tested yet