add passive pattern, fixed a bug in "?" function, add tests make logic more testable