Devices: fix wrongly placed assert and device count iteration

Fix for potential problems