Fix crash by using reference instead of pointer