Move initialisation code to functions
Remove redundant line

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

avoids code duplication