cleaned up django views and helper function