finished factorial method