Check keys instead of values

Fixes #563