Various fixes from SCA

Performance related:
- prefer prefix ++operator for non-primitive types
- use !empty() instead of size() 

Other:
- remove unused variables
- use static_cast<>() instead of C-Style casts