restructed the code