More smaller (style related) fixes

More smaller fixes:
- use static_cast instead of C-Style cast
- fix warning about 'Possible null pointer dereference'
- reduce scope of some variables
- Clarify calculation precedence for '%' and '?'
- clarify expression with parentheses
- remove assignment of a never used value
- remove some unused variables
- pass some const variables by reference
- remove consecutive return/break statement
- initialize some variables in constructor
- fix typo