organized the code
fixed glitch related to going offline/online multiple times failing after the first time
added comments and organized code