Added online and offline event handlers