Improve trap entry code