refactoring to make impl generic across stage and prod