State machine instead of boolean checks