Some improvements and bugfix.