Fixing compilation issues and minor refactoring.