Made error handling more simple and effective