Bug fix in cast