fixed defer bug