Fixed some situations that can lead to errors.