restructured to be a little more modular, like mean example