clean code with GCC warning

Reducing a number of GCC warnings.

There are also a number of unused functions which I didn't touch.