match_forward function

refactoring some code