add support for custom defer-function, fix yet one more bug