Refactor device management