Adding imperative version of the factorial