Improve routing logic and move to separate file

Regexes are now defined once rather than compiled for every request