POSIX trap behavior

Reverted to POSIX style function definitions, and added explicit trap
reset (in case the shell is changed to sh/bash).