vectorized some formulas, needs correctness checking