Fix NPE in mapToMapWritable function