Restructured #if macros 
Removed unneeded extern scope
Fixed signal + wait which could trigger a deadlock