improving readability and performance

small refactoring by @dhh suggestion