warning fixes and refactoring