added comments and recursive factorial function