Added initialize

Changed existing function and added domevent listener to detect window
loading.