refactoring and warning fixes