Added collision checking code.