Fixed some bugs and a regression.