Fixed some minor bugs for flag = 4