refactorings, removed SQL from flow