Refactor trap.rb