Rewrite Cas class

Fix #264