Many bugs fixed