Fix crash bug in ray casting

The fix stops a map from being incorrectly being treated as if it was a vector.
Add some const correctness to ray casting