added better looking safe casting function templates