More error checking - no crashing this time hopefully.