cache code, some other fixes. Cache code is not implemented yet.