Add test case for #172.
Remove unsafe thunk optimization; fixes #172, #123.