fix delegation logic bugs;  improve test coverage