Updated with device detection awareness.