Added #define generation and a few fixes