Refactor `map` and `record` rules. Update tests.