Added JSON output and improved algorithm with numeric parsing.