Implemented a TMP version of factorial.