Made various private functions/globals static, to fix clang warnings
fix warning about comparisions of types with different sigedness/size by changing type of one
removed dead/unreachable code
Fixed warning about unused macros by putting their declaration in the same #if as their usage
Made various private functions/globals static