simplify where clause a bit and fix test