Another fix for issue #20: more robust matrix parsing

- separated number parsing into a function
- more robust parse logic for matrix