Adds full pre-Model Relay support for input mapping.
Refactors the structure of the module for better factoring.