Added auto token updating, fixed a few memory leaks