Fix some logic problem