Added factorial algorithm