great function
just a little bug
I want to get rid of Ref error