code refactoring and ir learn routing enhancements