Ported basic token support

Also cleaned up some code