Added comments. Added try/catch to XHR request to catch some weird bugs.