bug fix for function