Fix error handling bug. Need to add more error handling