Small changes and fixes. Fixed #582.