error handling changed, re rewritten