rearrange code to ensure layers load correctly