Add post canceling API, with some refactoring