Move javascript to its own function in its own file