Refactor to reduce inline code