Refactor javascript on devices page