refactored device factory