code reorganization (dependencies first), chaining. TODO:fix postgres.