added some documentation, moved functions around, redid the reconnect function