State logic pseudocode