add function and fix bug