refactoring deferred code for simplicity