Improvements and bugfix.