Fixed the ray casting algorithm