Some more error handling (still not perfect)