Refactoring: resolved some dependencies and removed unused includes/global variables in some files.

Compiled on Linux and Windows.