Fix bug in casting operation