trap entry refactoring