change fn to factory