Improvements and fixes for previous code.