fixed dangling ref bug