Reduce number of function calls on resize event and other optimisations