fixed almost everything

some glitches still there.
**urgent need to restructure the code.