add function to factor and factor to pgm