Cleaned up code.
Added some comments
Fixed auto reconnect again, it works now, honest :)