Fix bugs in collosion detection and resolution.