cleaned up source, added upgrade token support