     }
     
     private func advance() -> Character {
-        current += 1
-        let cs = source.characters
-        return cs[cs.index(cs.startIndex, offsetBy: current - 1)]
+        let result = source[current]
+        current = source.index(after: current)
+        return result
     }
     
     private func addToken(_ type: TokenType) {

            while isDigit(peek()) { let _ = advance() }
        }
        
        let cs = source.characters
        let strvalue = String(cs[cs.index(cs.startIndex, offsetBy: start)..<cs.index(cs.startIndex, offsetBy: current)])
        
        addToken(.NUMBER, Double(strvalue)!)
    }

    private func identifier() {
        while (isAlphaNumeric(peek())) { let _ = advance() }
        
        let text = source[start..<current]
        
        let type = Scanner.keywords[text] ?? .IDENTIFIER
        addToken(type)
