Rewrote patient selection logic.