Replace duplicate code with calls to getOrPushAttribute().