Error Handling

Added some error handling.