improved code, very beginnings of collision detection