Fix where/repeat handling. Bug fixes.