rewrite for cocos;