Fixed some bugs caused by peter's old bugs.