Remove unused variable
Remove unused functions and parameters
Move initialisation code to functions
Remove redundant line

localStorage triggers this on page load anyway
Reorder statements for easier reading
Move mobile device detection to a function

avoids code duplication