refactorings and correcting a few warnings