Intermediate patches to correct some bugs