added all global variables into one object, changed sending data format, other minor fixes.
NEED CONFIRMATION THAT EVERYTHING WORKS