minor refactoring after Todds suggestion