Add tests and fix some bugs for limit and sigma