casting function added, as an alternative for asInstanceOf @vjovanov

I'm not sure if this is what you meant, if you confirm that it is, then the whole code would be changed to use this function...