my solution refactored with reverse method