Some validations and refactioring