1.0.4.13: refactor trap handling