implement all functions, but erode has some bugs