updated codes
Fixed bugs