added iterate.flattened, and changed database session decorator.