Refactors to mimic Tom's elegant solution