Some (code) improvements

This pull request contains some code improvements - no new features.

*Please see commit messages for list of changes.*

I've also added `-Wall` and `-Wextra` flags, since they provide many useful warnings (those are already fixed within this request).