updated, used recursion instead of for statement for factorials