Fixes compiler errors and warnings on Mac OS X compile

Mainly unused vars and logic parentheses.

Please check the logical parentheses carefully to make sure I understood the logic!