Fixes bug in token logic (fixes issue #10). Also closes issue #2.