Fix NULL value for setFlags and refactoring