Beginning of input router logic