changed onregister and onderegister to initialize and destroy respectively