Reorganised code, added registering and unregistering methods