Improvements based on Turini's suggestions.