Improved the number parsing function