improving readability and performance

small refactoring by @dhh suggestion
comments by @reed