code has been restructualized and verified