Fixed some bugs, subtler ones still in.