improved ema calculation flow