modified validate functon after testing it.