Refactor generator for clarity.
Fix routing in data link layer and added tests.