Fix buggy code