Fixed some serious bugs in master.