refact with err done fucntion