Refactored common code in handlers/base.py and urlresolvers.py