Finally fixed all the raycasting bugs