Refactored trap handler again