many changes needed to make this compatible with django 1.5