Fix some bugs.
Add test case for SAE.