[Devices Management] Refactor some code to improve testability