Fixing compiler issues, and minor refactoring