Tested using csmith generated codes. Several bug fixes.