fix factorial and added comments