 		initialize: () ->
 
 
+			window.onbeforeunload = () =>
+				if @exitNetwork()?
+					return undefined
+
 			@timers = []
-			setInterval(@_updatePosition, @_updatePositionInterval)
-			setInterval(@_ensureNetworkIntegrity, @_ensureNetworkIntegrityInterval)
-			setInterval(@_recommendParent, @_recommendParentInterval)
+			@timers.push(setInterval(@_updatePosition, @_updatePositionInterval))
+			@timers.push(setInterval(@_ensureNetworkIntegrity, @_ensureNetworkIntegrityInterval))
+			@timers.push(setInterval(@_recommendParent, @_recommendParentInterval))
 
 
 			@_parent = null

				for child in @getChildren()
					@removeChild(child)

				# Select a new parent.
				@_selectParent()

		# Is called when a peer disconnects. Will make sure we handle this
		# disconnect in the appropriate manner.

			else
				@token.candidates = []
				@setSuperNode(true)

		clearIntervals: () ->
			for timer in @timers
				clearTimeout(timer)
