some refactoring and cleanings