refactor use defer