Extensive refactoring, cleanup. Remove presumptions of Django.