Several minor bugs fixed