modified trap.c to make it work