Some bugs fixed by dennis