factor kalman code out from test into example