Refactoring based on Turini's suggestions.