Refactoring based on Garcia's suggestions.