refactor lifecycle