moved most of the startup into the OnRegistered function