fixed bug in function