fix warnings and errors found with -Wall -Wextra

- fixed code paths that resulted in use of uninitialized variables
- fixed unchecked comparisons between signed and unsigned vars
- marked unused params
- moved static functions out of header files
- removed useless "const" modifier on integral return values