Minor refactoring based on Lucas's suggestion.