updated code to load at the right times