add imperative style factorial