Improved #ifdef placement, and error handling.