Fix build warnings

- Fix duplicate declarations of many variables
- Fix quite a few function calls missing their ()s
- Fix other miscellaneous warnings, build should be error free.