Fixes for dtype casting

Fixes #264 
Fixes #259 (casting of masked arrays)