Reduce scope of some preprocessor directives, remove some unreachable code
and minor code formatting changes.