split off a lot of private functions