updating final code for validation