Improved code to map dict to struct