fix preroute and preroute_exec functions
switch to use create_function instead of closure
fix comments and code style