Optimize code: Fix Constructor to determine illegal logic problems (#3197)