Fixed bugs in pagination library and did some micro optimization to routing function.