closes #33: factor out function  from ,  and