unsafe reference causing exception fix