added npe catching in cast()