1. moved router functions to local scope
2. added AMD to routes handling so that js loaded on the fly