the code works and verified started to restructuralize the code