Made the parsing code a bit more robust
Fixed undefined variable
Fixed variable name typo
Refactored and extended the tests