Working version perhaps?  Needs testing.