Refactor device state checking