Fixed syntax issues and review critics, put all the debugging code in a #define block