Refactor struct and array code