Moved onFlag() to its own class