buggy reorganized code