Some code from router.rb → utils