Fixes reference access on function return