use record instead of just map
Improve error reporting