minor refactoring and correcting