Fixed some bugs, maybe introduced others.