add saturated math and fix some small issues