Numerous bugs fixed