optimize on enter and major refactor