btw very careful here, none of this is unit tested.