restrucuted the code