Unless there's a compact, self-contained example that can be compiled independently of your environment, your macros, and so on, you shouldn't expect a meaningful answer.
Especially since there's no question. "What am I doing wrong" is meaningless without the context of "what do I want to achieve?" (That's unclear after a quick review of your code, and expecting someone to spend hours on it is also pretty unreasonable.)
Unless there's a compact, self-contained example that can be compiled independently of your environment, your macros, and so on, you shouldn't expect a meaningful answer.
Especially since there's no question. "What am I doing wrong" is meaningless without the context of "what do I want to achieve?" (That's unclear after a quick review of your code, and expecting someone to spend hours on it is also pretty unreasonable.)