Some improvements and bug fixes