dir-iterator: refactor state machine model