refactored router a bit to support patch