added and modified all code but some bugs. Need to debug