Querying elements in a typesafe manner