added the refactoring from Robert Jackson