Made error handling nicer