Added error handling

closes #143
closes #296