Re-organize code for routing