refactored load_struct function