Refactoring and fixed some validations