Refactor code and fix bugs.
Move router code to separate file.
Fix antipattern of checking for file existence before loading.