rewrote cote

Some bug fix and improvment