Fix bugs caused by e287a9f and d52c3ee