moving code for factorial to separate class