refactorings from @tenderlove