Fixing some exception handling