Adding validation and logging