Fix some smaller style issues

Fixing some issues like:
- use static_cast instead of C-Style cast
- pass const string by refrence
- remove some unused variables
- reduce the scope of some variables
- check for self assignment in operator=
- remove some unreachable break statements
- remove duplicate if/else branches