A ton of fixes especially for error handling