Created an imperative reverse implementation