Fix many bugs of recent modifications