improving readability and performance

small refactoring by @dhh suggestion
comments by @reed
Merge pull request #231 from keram-refinery/refactoring

improving readability and performance