cleaned up factorial helper