refactoring and removed all warnings