move validation to a separate file and use setTimeout for validation