Refactoring the code.
Add forward mode.