Added some failsafe stuff.