Bugfixes

Two bugs were due to new caching behaviour; I also fixed (or tried to fix :) ) some failing tests among codegen tests.