code reorganization for readability
code correction to use correct contante in routing process