fix bugs when using reference, now is a stable version