adding another implementation of safe cast