Fixed a bug in contact detection.