correct bug in function