fix buggy code