Added a better solution for factorial