Added error and tokenization handling