Fix dirty tracking (v2)

Second version of the previous attempt. This leaves out the typecasting of default values (as per discussion with dkubb and solnic). Those default values should probably be checked for the correct type, but I'm putting that on hold for now (the type classes don't specify any type to check against; and for blocks it is even more difficult).