Added smarter collision detection