added edge collision detection