code fix

code structed and some other fixes