Some refactoring and clean code