Safer casting in operator= (closes #146)