various devicestate fixes (issue #5081, take two)