fixed code for validation