Made some minor changes to reduce the potential for crashes