Moved all JS initialisation to a seperate function