Refactor to simplify
R