Added exception handling; fixed bug when parsing with ifstream