Cleaning up BaseHandler.

* Sort imports in basehandler.
* Use str.endswith instead of slicing.
Remove unused functions and unused args fom field handler.