Slight optimization
Slight optimization
Factored out common code
Merge pull request #366 from mslinn/master

Slight optimization