Modified code to use a struct