Some improvements and bugs fixed